// components/food-list/food-list.ts
Component({
  options: {
    styleIsolation: 'shared'
  },
  properties: {
    foods: {
      type: Object
    },
    isShowBtn: {
      type: Boolean,
      value: true
    }
  },
  data: {
    detail: {},
    isShowDetail: false
  },
  methods: {
    onPlus(event: any) {
      const id = event.currentTarget.dataset.id
      const food = this.properties.foods.find((item: any) => item.id === id)
      food.count += 1
      this.triggerEvent('onFoodChange', food)
    },
    onMinus(event: any) {
      const id = event.currentTarget.dataset.id
      const food = this.properties.foods.find((item: any) => item.id === id)
      food.count -= 1
      this.triggerEvent('onFoodChange', food)
    },
    onShowDetail(e: any) {
      this.setData({
        detail: e.currentTarget.dataset.food,
        isShowDetail: true
      })
    },
    onCloseDetail() {
      this.setData({
        isShowDetail: false
      })
    }
  }
})
